<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">收货站点</span>
                <el-input v-model="tableParam.receiveStation" style="width: 220px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">物料名称</span>
                <el-input v-model="tableParam.rawName" style="width: 220px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">状态</span>
                <el-select v-model="tableParam.receiveStatus" style="width: 220px;" placeholder="请选择">
                  <el-option v-for="item in statuslist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="tableParamType = true">高级搜索</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div></div>
            <div>
              <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
                <el-link :underline="false">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_filtrate"></i>
                  </span>
                  筛选
                </el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item, index) in table" :key="index">
                    <el-checkbox v-model="item.status">{{ item.label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
                <span class="el-icon--left">
                  <i class="iconfont iconicon_button_export1"></i>
                </span>
                导出
              </el-link>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label == '异常处理'||item.label == '操作'?'right':false">
                  <template slot-scope="scope">
                    <span v-if="item.label == '状态'" style="color:#969799;">{{ statuslist | fromatTable(scope.row.receiveStatus,'itemName','id')}}</span>
                    <el-button v-else-if="item.label == '异常处理'&&ButtonList.findIndex(res=>(res.buttonValue=='CKYCCL'))!==-1" size="mini" class="bottom_one" @click="gettestresult(scope.row)">查看异常处理</el-button>
                    <span v-else-if="item.label == '交货量照片'">
                      <el-button v-if="scope.row.imgs" class="bottom_one" size="mini" @click="show1(scope.row.imgs,'交货量照片')">查看</el-button>
                    </span>
                    <span v-else-if="item.label == '材质书'">
                      <el-button v-if="scope.row.materialBookUrl" size="mini" class="bottom_one" @click="show1(scope.row.materialBookUrl,'材质书照片')">查看</el-button>
                    </span>
                    <span v-else-if="item.label == '附件'">
                      <el-button v-if="scope.row.accessoryUrl" size="mini" class="bottom_one" @click="show1(scope.row.accessoryUrl,'附件照片')">查看</el-button>
                    </span>
                    <span v-else-if="item.label == '操作'">
                      <el-button class="bottom_one" size="small" @click="queryListBysupplierIdFun(scope.row)">修改计划</el-button>
                    </span>
                    <!-- <el-button v-else-if="item.label == '检测结果'" size="mini" class="bottom_one" @click="changeline(scope.row)">生产线维护</el-button> -->
                    <span v-else>{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
          <div class="card_bottom">
            <div class="card_bottom_left">
              <div class="top_page_totle">总共{{ total }}条</div>
              <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
            </div>
            <div>
              <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="activedialog" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">异常处理</span>
      <div class="dialoginfo">
        <div class="textline">
          <div class="left">异常现象：</div>
          <div class="right">{{results.phenomena}}</div>
        </div>
        <div class="textline">
          <div>原因：</div>
          <div>{{results.cause}}</div>
        </div>
        <div class="textline">
          <div>拟处理方式：</div>
          <div>{{results.processMode}}</div>
        </div>
        <div class="textline">
          <div>条件接收方式：</div>
          <div>{{results.acceptableConditings}}</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="activedialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 高级搜索 -->
    <el-dialog v-dialogDrag :visible.sync="tableParamType" width="650px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">高级搜索</span>
      <div class="dialoginfo">
        <el-form ref="reftableParam" :inline="true" :model="tableParam" label-width="110px">
          <el-form-item>
            <span slot="label">供应商</span>
            <el-input v-model="tableParam.supplier" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">合同编号</span>
            <el-input v-model="tableParam.contractNo" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">交货车辆</span>
            <el-input v-model="tableParam.deliveryVehicl" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">司机</span>
            <el-input v-model="tableParam.driver" tplaceholder="请输入" clearable style="width:400px;"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">实际交货时间</span>
            <el-date-picker v-model="startTimDateEndTimDate" type="datetimerange" unlink-panels value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" @change="tableParam.intoTime=startTimDateEndTimDate[0]||'',tableParam.outTime=startTimDateEndTimDate[1]||''"></el-date-picker>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="tableParamType=false,tableParam.supplier='',tableParam.contractNo='',tableParam.deliveryVehicl='',tableParam.driver='',startTimDateEndTimDate=[],tableParam.intoTime='',tableParam.outTime=''">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="gettableData(),tableParamType=false">搜 索</el-button>
      </span>
    </el-dialog>
    <!-- 查看图片 -->
    <ShowDetails :dialog="imgsDialog" :imgsText="imgsText" :imgList="imgList" :mp4List="mp4List" :fileList="fileList" @reset="reset"></ShowDetails>
    <!-- 修改计划 -->
    <el-dialog v-dialogDrag :visible.sync="modifyType5" width="450px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">修改计划</span>
      <div class="dialoginfo">
        <el-form ref="modifyForm5" :model="modifyForm5" label-width="100px">
          <el-form-item label="供应计划：" prop="rawNeedId" :rules="[{required: true,message: '请选择供应计划',trigger: 'change',}]">
            <el-select v-model="modifyForm5.rawNeedId" @change="planIdFun(modifyForm5.rawNeedId)">
              <el-option v-for="item in planIdList" :key="item.id" :label="item.station+'_'+item.rawName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="站点：">
            <span>{{modifyForm5.station}}</span>
          </el-form-item>
          <el-form-item label="供应商名称：">
            <span>{{modifyForm5.supplierName}}</span>
          </el-form-item>
          <el-form-item label="原物料名称：">
            <span>{{modifyForm5.rawName}}</span>
          </el-form-item>
          <el-form-item label="原物料规格：">
            <span>{{modifyForm5.specification}}</span>
          </el-form-item>
          <el-form-item label="需求时间：">
            <span>{{modifyForm5.needDate}}</span>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="modifyType5 = false">取 消</el-button>
        <el-button class="bottom_all" @click="makeupdatePlanFun()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import ShowDetails from '@/components/showdetails';
import {
  queryPage2,
  Download2,
  getConsignmentIssue,
  queryListBysupplierId, makeupdatePlan
} from "@/api/GHnumber/goods.js";
export default {
  mixins: [mixin],
  components: {
    ShowDetails
  },
  data() {
    return {
      imgsDialog: false,
      imgsText: '',
      imgList: [],
      mp4List: [],
      fileList: [],
      startTimDateEndTimDate: [],
      tableParamType: false,
      /*表格增删改查及下载接口*/
      queryPage: queryPage2,
      DownloadURL: Download2,
      /*表格数据*/
      table: [
        { label: "收货站点", width: "120", prop: "receiveStation", status: true, },
        { label: "供应商", width: "160", prop: "supplier", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "合同编号", width: "180", prop: "contractNo", status: true },
        { label: "协作单位", width: "140", prop: "cooperativeUnit", status: true, },
        { label: "物料名称", width: "120", prop: "rawName", status: true },
        { label: "规格", width: "120", prop: "specification", status: true },
        { label: "货票量", width: "120", prop: "ticketNum", status: true },
        { label: "过磅量", width: "120", prop: "weighingNum", status: true },
        { label: "收货量", width: "auto", prop: "receiveNum", status: true },
        { label: "扣减量", width: "120", prop: "deductionNum", status: true },
        { label: "含水率", width: "auto", prop: "moistureContent", status: true, },
        { label: "备注", width: "120", prop: "remark", status: true },
        { label: "交货车辆", width: "auto", prop: "deliveryVehicl", status: true, },
        { label: "司机", width: "120", prop: "driver", status: true },
        { label: "实际收货时间", width: "160", prop: "actualReceiveTime", status: true, },
        { label: "进场时间", width: "160", prop: "intoTime", status: true },
        { label: "离场时间", width: "160", prop: "outTime", status: true },
        { label: "卸料仓", width: "120", prop: "repertory", status: true },
        { label: "收货地点", width: "160", prop: "receiveStationSite", status: true, },
        { label: "异常处理", width: "140", prop: "", status: true },
        { label: "异常评价", width: "400", prop: "evaluate", status: true },
        { label: "操作", width: "120", prop: "", status: true },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        code: [{ required: true, message: "请输入站点编码", trigger: "blur" }],
      },
      fromDate: {
        code: "",
      },
      statuslist: [
        { itemName: "运输中", id: 1 },
        { itemName: "检验中", id: 2 },
        { itemName: "卸料中", id: 3 },
        { itemName: "内部确认中", id: 4 },
        { itemName: "外部确认中", id: 5 },
        { itemName: "已接受", id: 6 },
        { itemName: "退回", id: 7 },
      ],
      dialoglist: ["testresult"],
      activedialog: false,
      results: {},
      modifyType5: false,
      planIdList: [],
      modifyForm5: { rawNeedId: '', id: '' }
    };
  },
  async created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, rawName: "", receiveStation: "", receiveStatus: null, supplier: '', contractNo: '', deliveryVehicl: '', driver: '', intoTime: '', outTime: '' };
    this.gettableData();
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    planIdFun(id) {
      let item = this.planIdList.find((res) => res.id == id)
      this.modifyForm5.station = item.station
      this.modifyForm5.supplierName = item.supplierName
      this.modifyForm5.rawName = item.rawName
      this.modifyForm5.specification = item.specification
      this.modifyForm5.needDate = item.needDate
    },
    /**打开修改计划 */
    queryListBysupplierIdFun(row) {
      this.$nextTick(() => { this.$refs.modifyForm5.clearValidate() });
      this.$data.modifyForm5 = this.$options.data().modifyForm5
      this.modifyForm5.id = row.id
      this.modifyType5 = true
      queryListBysupplierId({ supplierId: row.supplierId }).then((res) => {
        this.planIdList = res.data
      })
    },
    /**提交修改计划 */
    makeupdatePlanFun() {
      this.$refs.modifyForm5.validate((valid) => {
        if (valid) {
          makeupdatePlan(this.modifyForm5).then((res) => {
            if (res.code == 1001) {
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.modifyType5 = false
              this.gettableData();
            }
          })
        } else {
          return false;
        }
      });
    },
    /**看图*/
    show1(file, text) {
      let items = file?.split(",").map(res => ('/file/' + res))
      this.imgList = items.filter(res => (res.includes('type=img')))
      this.mp4List = items.filter(res => (res.includes('type=mp4')))
      this.fileList = items.filter(res => (res.includes('type=file')))
      this.imgsText = text
      this.imgsDialog = true
    },
    reset(key) {
      this[key] = false;
    },
    init() {
      /*重置数据*/
      this.tableParam.rawName = "";
      this.tableParam.receiveStation = "";
      this.tableParam.receiveStatus = null;
      this.gettableData();
    },
    gettestresult(low) {
      this.activedialog = true
      getConsignmentIssue({ consignmentId: low.id }).then((res) => {
        this.results = { ...this.results, ...res.data };
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.textline {
  line-height: 40px;
  display: flex;
  > div:first-child {
    width: 100px;
    text-align: right;
  }
  > div:last-child {
    width: 500px;
  }
}
.table_link {
  margin-left: 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}
.el-input,
.el-select {
  width: 240px;
}
</style>
